<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>A2P</title>
<link href="css/styles_menu.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
/* Terence Ordona, portal[AT]imaputz[DOT]com		 */
/* http://creativecommons.org/licenses/by-sa/2.0/	*/
/* begin some basic styling here					 */
body {
	background: #FFF;
	color: #000;
	font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif;
	margin: 10px;
	padding: 0
}
table, td, a {
	color: #000;
	font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif
}
h1 {
	font: normal normal 18px Verdana, Geneva, Arial, Helvetica, sans-serif;
	margin: 0 0 5px 0
}
h2 {
	font: normal normal 16px Verdana, Geneva, Arial, Helvetica, sans-serif;
	margin: 0 0 5px 0
}
h3 {
	font: normal normal 13px Verdana, Geneva, Arial, Helvetica, sans-serif;
	color: #008000;
	margin: 0 0 15px 0
}
/* end basic styling								 */
/* define height and width of scrollable area. Add 16px to width for scrollbar		 */
div.tableContainer {
	clear: both;
	border: 1px solid #963;
	height: 285px;
	overflow: auto;
	width: 756px
}
/* Reset overflow value to hidden for all non-IE browsers. */
html>body div.tableContainer {
	overflow: hidden;
	width: 756px
}
/* define width of table. IE browsers only				 */
div.tableContainer table {
	float: left;
	width: 740px
}
/* define width of table. Add 16px to width for scrollbar.		  */
/* All other non-IE browsers.										*/
html>body div.tableContainer table {
	width: 756px
}
/* set table header to a fixed position. WinIE 6.x only									  */
/* In WinIE 6.x, any element with a position property set to relative and is a child of	  */
/* an element that has an overflow property set, the relative value translates into fixed.	*/
/* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */
thead.fixedHeader tr {
	position: relative
}
/* set THEAD element to have block level attributes. All other non-IE browsers			*/
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
html>body thead.fixedHeader tr {
	display: block
}
/* make the TH elements pretty */
thead.fixedHeader th {
	background: #C96;
	border-left: 1px solid #EB8;
	border-right: 1px solid #B74;
	border-top: 1px solid #EB8;
	font-weight: normal;
	padding: 4px 3px;
	text-align: left
}
/* make the A elements pretty. makes for nice clickable headers				*/
thead.fixedHeader a, thead.fixedHeader a:link, thead.fixedHeader a:visited {
	color: #FFF;
	display: block;
	text-decoration: none;
	width: 100%
}
/* make the A elements pretty. makes for nice clickable headers				*/
/* WARNING: swapping the background on hover may cause problems in WinIE 6.x  */
thead.fixedHeader a:hover {
	color: #FFF;
	display: block;
	text-decoration: underline;
	width: 100%
}
/* define the table content to be scrollable											 */
/* set TBODY element to have block level attributes. All other non-IE browsers			*/
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
/* induced side effect is that child TDs no longer accept width: auto					 */
html>body tbody.scrollContent {
	display: block;
	height: 262px;
	overflow: auto;
	width: 100%
}
/* make TD elements pretty. Provide alternating classes for striping the table */
/* http://www.alistapart.com/articles/zebratables/							 */
tbody.scrollContent td, tbody.scrollContent tr.normalRow td {
	background: #FFF;
	border-bottom: none;
	border-left: none;
	border-right: 1px solid #CCC;
	border-top: 1px solid #DDD;
	padding: 2px 3px 3px 4px
}
tbody.scrollContent tr.alternateRow td {
	background: #EEE;
	border-bottom: none;
	border-left: none;
	border-right: 1px solid #CCC;
	border-top: 1px solid #DDD;
	padding: 2px 3px 3px 4px
}
/* define width of TH elements: 1st, 2nd, and 3rd respectively.		 */
/* Add 16px to last TH for scrollbar padding. All other non-IE browsers. */
/* http://www.w3.org/TR/REC-CSS2/selector.html#adjacent-selectors		*/
html>body thead.fixedHeader th {
	width: 200px
}
html>body thead.fixedHeader th + th {
	width: 240px
}
html>body thead.fixedHeader th + th + th {
	width: 316px
}
/* define width of TD elements: 1st, 2nd, and 3rd respectively.		 */
/* All other non-IE browsers.											*/
/* http://www.w3.org/TR/REC-CSS2/selector.html#adjacent-selectors		*/
html>body tbody.scrollContent td {
	width: 200px
}
html>body tbody.scrollContent td + td {
	width: 240px
}
html>body tbody.scrollContent td + td + td {
	width: 300px
}
-->
</style>

<script src="js/jquery-1.3.1.min.js" type="text/javascript"></script>
<script src="js/jquery.functions.js" type="text/javascript"></script>

<style type="text/css">
a{
	text-decoration:none;
}
img{
	border:none;
}
#contenedor{
	width:800px;
	margin:auto;
	margin-top:20px;
	border:2px solid #C0C0C0;
	background-color:#F2F2F2;
	padding-bottom:20px;
}
small{
	font-size:9px;
}

table{
	width:700px;
	margin:auto;
}
td{
	
	padding:5px 0px 5px;
	text-align: left;
}

th{
	background-color:#CDCDCD;
	padding:5px 0px 5px;
}

form{
	border:2px solid #C0C0C0;	
	width:500px;
	margin:auto;
	margin-bottom:20px;
}

form p{
	margin:auto;
	width:450px;
	margin-top:5px;
	margin-bottom:3px;
}
form input{
	border:1px solid #CCCCCC;
	padding:3px;
}

form .text{
	width:400px;
}

#resultado{	
	border:none;
}

.textos {
	text-align: left;
}
.textos label {
	text-align: left;
}

iframe{
		visibility:hidden;
	display:none;	
}

.frame{
	visibility:hidden;
	display:none;	
}

	.progress-bar {
     border: 1px solid #56577A; 
     width: 200px; 
     margin: 5px; 
     padding: 1px; 
     background: #fff;
	 float: left;
	 text-align:center;
   }

   .bar {
     height: 15px;
	 font-size: 11px;
	 text-indent:-9000px;
	 text-align:center;
   }
   
   #percentage{
    float: left;
	margin-left: 10px;
	margin-top:4px;
   }
</style>
<script src="progressbar.js" type="text/javascript"></script>
<script type="text/javascript">
var prefijos = new Array();
<?php 
$index2 =0;
$conexion = mysql_connect("localhost", "admin", "Xurpas123");
mysql_select_db("smsnic", $conexion);
$result1= mysql_query("SELECT prefijos FROM movistar", $conexion) or die(mysql_error());
if (mysql_num_rows($result1)){ 
$i=0;
while ($row1 = @mysql_fetch_array($result1)){
echo "prefijos[".$i."] = ".$row1['prefijos'].";";
$i=$i+1;
}

}

mysql_close($conexion);
?>



function enviar(){

	var telefonos = document.getElementById('msisdn').value;
	var elem = telefonos.split('\n');
	var mensaje = document.getElementById('sms');
	var x = 0;
	var testFrame = new Array();
	var audi = new Array();
	var frame ="";
	
		var seleccionado = document.getElementById('seleccionado').value;
	var edad = 0;
	var edad2 = 0;
	
	if(seleccionado==1)
	{
			edad =  document.getElementById('edad').value;
		}
		else if (seleccionado == 2)
		{
			edad =  document.getElementById('edad2').value;
			}
		else if (seleccionado == 3)
		{
			edad =  document.getElementById('edad3').value;
			edad2 =  document.getElementById('edad4').value;
			}
	
	if(mensaje.value=="")
	{
		alert("No ha ingresado el mensaje que se enviara...");
	}
	else
	{
		for(var i=0; i< elem.length; i++) 
		{		
		x=0;	
			for(var j=0; j < prefijos.length; j++)
				{
			
					if(elem[i].substring(0,4)==prefijos[j])
						{	
						
							x=1;
							
							audi[i] = document.createElement("IFRAME");
							audi[i].id = "audi"+i;
							frame="audi"+i;
							audi[i].src = "envios.php?telefono=505"+elem[i]+"&operadora=1&mensaje="+mensaje.value+"&estado=1&seleccionado="+seleccionado+"&edad="+edad+"&edad2="+edad2;	
							document.body.appendChild(audi[i]);
							document.getElementById(frame).className='frame';	
						
						}
				
				}
				if(x==0){
					if(elem[i]!=""){
				
											
							audi[i] = document.createElement("IFRAME");
							audi[i].id = "audi"+i;
							frame="audi"+i;
							audi[i].src = "envios.php?telefono=505"+elem[i]+"&operadora=2&mensaje="+mensaje.value+"&estado=1&seleccionado="+seleccionado+"&edad="+edad+"&edad2="+edad2;	
							document.body.appendChild(audi[i]);
							document.getElementById(frame).className='frame';
													
					}
							
				}
	
		}

		initialize();
		
	}	
}

function cargar(){

	var indice = document.getElementById('grupo').selectedIndex;
	var grupo = document.getElementById('grupo').options[indice].value;	
	


	<?php
if(isset($_GET['grupo'])){
	?>
	document.location.href="sms.php?grupo=<?php echo $_GET['grupo']; ?>,'"+grupo+"'";
	<?php
}
else{
	?>
	document.location.href="sms.php?grupo='"+grupo+"'";
	<?php
}
?>

}
function agregar(x){
	var variable = document.getElementById('var'+x);
	var msg = document.getElementById('sms');
	msg.value=msg.value+variable.name
	
	
}
//variable del sistema
function agregarVS(x){

	var msg = document.getElementById('sms');
	msg.value=msg.value+x;
	
	
}
function cambiar(){

id=document.getElementById("condicion").value;
alert(id);
		if(id=="0")
	{
	
	div = document.getElementById('Dcondicion');				
				div.style.display='none';
				
	
		div3 = document.getElementById('Dcondicion3');
		div3.style.display = 'none';
		
		div2 = document.getElementById('Dcondicion2');
		div2.style.display = 'none';
	}
	else if (id=="1")
	{
				
		div = document.getElementById('Dcondicion');
		document.getElementById('seleccionado').value= document.getElementById('condicion').value;

		div.style.display = '';
		
		div3 = document.getElementById('Dcondicion3');
		div3.style.display = 'none';
		
		div2 = document.getElementById('Dcondicion2');
		div2.style.display = 'none';
		}
		else if (id=="2")
	{
				
		div = document.getElementById('Dcondicion2');
		document.getElementById('seleccionado').value= document.getElementById('condicion').value;

		div.style.display = '';
		
		div3 = document.getElementById('Dcondicion3');
		div3.style.display = 'none';
		
		div1 = document.getElementById('Dcondicion');
		div1.style.display = 'none';
		}
		else if (id=="3")
	{
				
		div = document.getElementById('Dcondicion3');
		document.getElementById('seleccionado').value= document.getElementById('condicion').value;

		div.style.display = '';
		
		div2 = document.getElementById('Dcondicion2');
		div2.style.display = 'none';
		
		div1 = document.getElementById('Dcondicion');
		div1.style.display = 'none';
		
		}
	
}

	function mostrarDIV()
	{
		div = document.getElementById('Dcondicion');
		document.getElementById("rp").value=id;
		div.style.display = "";
		}
		
		function ocultarDIV() {

				div = document.getElementById('Dcondicion');
				
				div.style.display='none';

		}
		
		
		
		<?php
		if(isset($_GET['grupo'])){
			?>
			function quitar(menos){
		
		document.location.href="sms.php?grupo=<?php echo $_GET['grupo']; ?>".replace(menos, "");
			
			
		}
		
		
		function cadcompare(){
			var indice = document.getElementById('grupo').selectedIndex;
	var grupo = document.getElementById('grupo').options[indice].value;	
	 if("<?php echo $_GET['grupo']; ?>".indexOf(grupo)!=-1)
	 {
		 alert("Ya agrego este grupo.");
		 return false;
	 }
	 else{
		 return true;
	 }
		
		}
			<?php
		}
		?>
		
		function ver(){
			return false;
		}
		
</script>
</head> 

<body bgcolor="#FFFFFF" id="send_sms"> 
<iframe id="mov" height="1px" style="visibility:hidden">
</iframe>

<table align="center">
<tr>
<td colspan="3">
<form action="Javascript: cargar();" method="get" class="textos" style="border:none;" onsubmit="return cadcompare();">
<label>Seleccione un grupo:<select style="width:auto" id="grupo">
<?php
$conexion = mysql_connect("localhost", "admin", "Xurpas123");
mysql_select_db("smsnic", $conexion);
$result1= mysql_query("SELECT * FROM grupos", $conexion) or die(mysql_error());
if (mysql_num_rows($result1)){ 
while ($row1 = @mysql_fetch_array($result1)){
	$dato = $row1['nombre'];
echo "<option value=".$row1['nombre'].">";
echo $dato;
echo "</option>";
}

}
mysql_close($conexion);
if(isset($_GET['grupo'])){ 
$index2 = $_GET['id_sel'];
$grupo=$_GET['grupo'];

}
?>
</select></label>&nbsp;&nbsp;&nbsp;<input type="submit" value="Cargar Grupo" /><br/>
</form></td>
</tr>
<?php
if(isset($_GET['grupo']))
{
?>
<tr>
<td colspan="3">
<form onsubmit="return ver();" id="grupos">
<?php
$x="";
$grupo1 = explode(',', $_GET['grupo']);
foreach ($grupo1 as $value)
{
	if($value != ''){
	
	echo "<input type=\"submit\" value=\"".str_ireplace("'", "", $value)."\" id=\"$value\" onclick=\"quitar(this.id);\"/>";
	
	$x=$value;
	}
}
if($x==""){
	?>
	<script>
	document.getElementById('grupos').style.visibility="hidden";
	</script>
	<?php
}
?>
</form>
</td>
</tr>
<?php
}
?>
<form action="Javascript: enviar();" method="get" class="textos" style="border:none;" >
<tr>
<td width="255px" valign="top">
<label>T&eacute;lefonos:<br/>

<textarea class="text" type="text" name="msisdn" id="msisdn" style="height:265px; width:205px;max-height:267px; max-width:205px;" cols="8" ><?php if(isset($_GET['grupo'])){ 
$grupo= "";

$grupo2 = explode(',', $_GET['grupo']);
foreach ($grupo2 as $valor)
{
	if($valor <> ''){
		$grupo = $grupo.$valor.", ";
	}
	
}
$max=strlen($grupo);
$grupo=substr($grupo, 0, $max-2);

if($grupo <> ""){
	$conexion = mysql_connect("localhost", "admin", "Xurpas123");
mysql_select_db("smsnic", $conexion);
$result1= mysql_query("SELECT telefono FROM
cliente inner join grupos on cliente.grupo=grupos.id where grupos.nombre in ($grupo)", $conexion) or die(mysql_error());  
if (mysql_num_rows($result1)){ 
while ($row1 = @mysql_fetch_array($result1)){
$dato = $row1['telefono'];
echo "$dato\n";

}

}
mysql_close($conexion);	
}



}
?>
</textarea>    
</label>

</td>
<td width="405px" valign="top">
<label>Mensaje: <div class="container4">
	<div class="menu4">

<ul>
<li class="system"><a href="#"><img src="css/system.png" align="absmiddle" width="20" /> Variables del Sistema</a>
	<ul>
		<li><a href="#" onclick="Javascript: agregarVS('@nombre ');"><table><tr><td align="center" width="20px"><img src="css/name.png" align="absmiddle" width="20px" /></td><td align="center">&nbsp;Nombre del Cliente</td></tr></table></a></li>
		<li><a href="#" onclick="Javascript: agregarVS('@cell ');" ><table><tr><td align="center" width="20px"><img src="css/phone.png" align="absmiddle"width="20px" /></td><td align="center">&nbsp;Celular del Cliente</td></tr></table></a></li>

	
	</ul>
</li>
</ul>

	</div>
	</div><br /><br />
    <textarea class="text" type="text" name="sms" id="sms" style="height:200px; width:305px;max-height:200px; max-width:305px;margin-top:3px;" cols="10" rows="50"  tabindex="0"></textarea>
    </label>
</label><br/><br/>
<label>Filtro por Edad:</label>

<select id="condicion" name="condicion" onchange="Javascript: cambiar();">
<option value="0">Todo el Grupo </option>
<option value="1">Mayores de </option>
<option value="2">Menor de </option>
<option value="3">Entre la edad de</option>
</select>
<input type="hidden" id="seleccionado" name"selecccionado" value="0" /><br /><br />
<div name="Dcondicion" id="Dcondicion" style="display:none;"  >
<label id="slash" name="slash" >Mayores de:</label>
<input type="text" name="edad" id="edad" style="width:30px"   maxlength="2" sise="2"  /> <label id="anios" name="anios" >años</label>

</div>
<div name="Dcondicion2" id="Dcondicion2" style="display:none;"  >
<label id="slash2" name="slash2" >Menores de:</label>
<input type="text" name="edad2" id="edad2" style="width:30px"   maxlength="2" sise="2"  /> <label id="anios2" name="anios2" >años</label>

</div>

<div name="Dcondicion3" id="Dcondicion3" style="display:none;"  >
<label id="slash3" name="slash3" >Entre la edad de:</label>
<input type="text" name="edad3" id="edad3" style="width:30px"   maxlength="2" sise="2"  /> <label id="anios3" name="anios3" > y </label><input type="text" name="edad4" id="edad4" style="width:30px"   maxlength="2" sise="2"  /> <label id="anios3" name="anios3" > años </label>

</div>
<br />
<br />
<div align="center">
<input type="submit" value="Enviar"/>
</div>
</td>
<td width="405px" valign="top">
<div id="tableContainer" class="tableContainer" style="width:auto">
<table border="0" cellpadding="0" cellspacing="0" style="width:auto" class="scrollTable">
<thead class="fixedHeader">
	<tr>
		<th style="color:#FFF; text-decoration:underline">Variables:</th>
	</tr>
</thead>
<tbody class="scrollContent">
<?php
$conexion = mysql_connect("localhost", "admin", "Xurpas123");
mysql_select_db("smsnic", $conexion);
$result1= mysql_query("SELECT * FROM variables", $conexion) or die(mysql_error());  
if (mysql_num_rows($result1)){ 
while ($row1 = @mysql_fetch_array($result1)){
?>
	<tr valign="top">
		<td valign="top""><a id="var<?php echo $row1['id'] ?>" href="#" name="<?php echo $row1['valor'] ?>" onclick="Javascript: agregar(<?php echo $row1['id'] ?>);"><?php echo $row1['var'] ?></a></td>
		
	</tr>
<?php
}
}
?>
    </tbody>
</table>
</div>

</td>

</tr>
<tr>
<td colspan="3" align="center" valign="middle">
<div class="progress-bar">          
    <div id ="sample" class="bar">100%</div>
  </div>
  <div id ="percentage"></div>
</td>
</tr>
</form>  
</table>

</body>
</html>
<script>
document.getElementById('grupo').selectedIndex='<?php echo $index2; ?>';
</script>